// 如果需要手动映射type和组件的关系，请在这里配置
const viewMap = {};

function barToUpperCase(str) {
    return str
        .split('-')
        .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
        .join('');
}

// 优先匹配 map，否则将自动匹配
export function parseViewName(component) {
    var viewName = viewMap[component.type];
    if (viewName) {
        viewName = 'Flow' + barToUpperCase(viewName);
    } else {
        viewName = 'Flow' + barToUpperCase(component.type);
    }
    return viewName;
}

// 返回唯一标识
export function getUUID() {
    return Math.random().toString(36).substr(3, 10);
}

// 获取nodeId
const typeList = ['start', 'end', 'condition'];

export function getNodeId(type) {
    const uuid = getUUID();
    if (typeList.indexOf(type) !== -1) {
        const str = type.replace(/-/g, '');
        return `${str}_${uuid}`;
    } else {
        return uuid;
    }
}
